
import pymysql.cursors

#设置数据库连接信息
connection = pymysql.connect(host='localhost',user='root',password='qwe123',db='pydb',charset='utf8mb4')
try:
    with connection.cursor() as cursor:
        # sql语句
        sql = "select name,url from link"
        count = cursor.execute(sql)
        print("total",count)

        # 查询数据集合
        newsList = cursor.fetchmany(size=3)
        print(newsList)
finally:
    connection.close();
